<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
session_start();
include_once("../config.inc.php");
include_once(__Modules_Path."/JSon.lib.php");
include_once(__Modules_Path."/UserSessions.lib.php");
include_once(__Modules_Path."/LogRecord.lib.php");
include_once(__DBConnect_File);

$strUserData = stripcslashes($_data["UserData"]);

$strCheckKey = base64_encode($strUserData)."##".$_data["PFSID"]."==".urlencode($_data["Link"])."||".$_data["PFHost"]."[".date("Y-m-d")."]";
$strCheckKey = md5($strCheckKey);
if($strCheckKey !== $_data["CheckKey"])exit("Check Key Error!! ( ".$strCheckKey." != ".$_data["CheckKey"]." )");

if($_data["PFSID"] != $_SESSION["Admin_PFSID"]){
	$_SESSION["Admin_PFSID"] = $_data["PFSID"];
}

$objJS = new Services_JSON();
$objUser = $objJS -> decode($strUserData);

$strCKey = $objUser -> ID."_".(string)(md5(time() + mt_rand(0, 10000)));
setcookie("Admin_CKey", $strCKey);
$_SESSION["Admin_Info"] -> CKey = $strCKey;

$_SESSION["Admin_Info"] -> ID = $objUser -> ID;
$_SESSION["Admin_Info"] -> Account = $objUser -> UserAcc;
$_SESSION["Admin_Info"] -> Name = $objUser -> UserName;
$_SESSION["Admin_Info"] -> MemberGroup = $objUser -> UserGroup;
$_SESSION["Admin_Info"] -> ParentID = $objUser -> ParentID;
$_SESSION["Admin_Info"] -> isShowAllReport = $objUser -> isShowAllReport;
$_SESSION["Admin_Info"] -> isSupple = 1;//$objUser -> isSupple;
$_SESSION["Admin_Info"] -> isLock = $objUser -> UserStatus;
$_SESSION["Admin_Info"] -> SpGroup = $objUser -> SpGroup;
$_SESSION["Admin_Info"] -> DirectorID = $objUser -> Layer5ID;
$_SESSION["Admin_Info"] -> Layer6ID = $objUser -> Layer6ID;
$_SESSION["Admin_Info"] -> DomainName = $_SERVER["HTTP_HOST"];

//將群組資訊存入 session
$_SESSION["Admin_Info"] -> GroupName = $objUser -> GroupName;
$_SESSION["Admin_Info"] -> ProgramID = $objUser -> ProgramID;
$_SESSION["Admin_Info"] -> ProgramPower = $objUser -> ProgramPower;

$_SESSION["Admin_Info"] -> GamePower = (array)$objUser -> GamePower;

$_SESSION["Admin_PFSID_Time"] = time();
$_SESSION["RdHttpHost"] = $_data["PFHost"];

//紀錄 Session
$intSID = UserSession_Start(session_id(), $_SESSION["Admin_Info"] -> ID, $_SESSION["Admin_Info"] -> MemberGroup, 0, 0, 0, 0, 0);
if($intSID === false)ErrMsgOutputHTML("LoginError", "", 1);

//記錄登入成功 Log
AddLogin_Log($objUser -> UserAcc, $_data["PFSID"], 90);

header("Location: ".$_data["Link"]);
?>